from aliyunsdkdysmsapi.request.v20170525 import SendSmsRequest
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.profile import region_provider
from django.conf import settings
import json
from PetNetadmin.celery import app



# 注意：不要更改
REGION = "cn-hangzhou"
PRODUCT_NAME = "Dysmsapi"
DOMAIN = "dysmsapi.aliyuncs.com"

acs_client = AcsClient(settings.ACCESS_KEY_ID, settings.ACCESS_KEY_SECRET, REGION)
region_provider.modify_point(PRODUCT_NAME, REGION, DOMAIN)
@app.task
def sms_phone_c(phone,code):
    smsRequest = SendSmsRequest.SendSmsRequest()
    smsRequest.set_accept_format('json')
    smsRequest.set_SignName("阿里云短信测试")
    smsRequest.set_TemplateCode("SMS_154950909")
    smsRequest.set_PhoneNumbers(phone)
    smsRequest.set_TemplateParam(json.dumps({"code":code}))
    smsResponse = acs_client.do_action_with_exception(smsRequest)  # 调用短信发送接口，返回json
    print(smsResponse)
